<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <title>HZQ-云平台管理系统</title>
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="importmap-type" content="systemjs-importmap" />
    <script type="systemjs-importmap">
      {
        "imports": {
          "dashboard": "http://localhost:10800/app.js",
          "hzq-system": "http://localhost:10805/app.js",
          "single-spa": "/static/utils/js/single-spa.min.js",
          "vue": "/static/utils/js/vue.js",
          "vue-router": "/static/utils/js/vue-router.min.js"
        }
      }
    </script>
    <link
      rel="preload"
      href="/static/utils/js/single-spa.min.js"
      as="script"
      crossorigin="anonymous"
    />
    <link
      rel="preload"
      href="/static/utils/js/vue.js"
      as="script"
      crossorigin="anonymous"
    />
    <script src="/static/utils/js/system.min.js"></script>
    <script src="/static/utils/js/amd.min.js"></script>
    <script src="/static/utils/js/named-exports.js"></script>
    <script src="/static/utils/js/named-register.min.js"></script>
    <script src="/static/utils/js/use-default.min.js"></script>
  </head>
  <body style="margin: 0px;">
    <script>
      ;(function() {
        var originalResolve = System.resolve
        var moduleMap = {}
        System.resolve = function(name) {
          return originalResolve.apply(this, arguments).then(resolved => {
            moduleMap[name] = resolved
            return resolved
          })
        }
        window.getPublicPath = function(name) {
          const url = moduleMap[name]
          console.log('url:  ' + url)
          if (url) {
            let index = url.lastIndexOf('/js')
            if (index < 0) {
              index = url.lastIndexOf('/')
            }
            index++
            console.log('getpublishPath: ' + url.slice(0, index))
            return url.slice(0, index)
          } else {
            throw Error(`Could not find url for module '${name}'`)
          }
        }
        // 服务启动注册到这里
        Promise.all([
          System.import('single-spa'),
          System.import('vue'),
          System.import('vue-router')
        ]).then(function(modules) {
          var singleSpa = modules[0]
          var Vue = modules[1]
          var VueRouter = modules[2]
          Vue.use(VueRouter)

          // 注册应用
          singleSpa.registerApplication(
            'dashboard',
            () => System.import('dashboard'),
            location =>
              location.pathname === '' ||
              location.pathname === '/' ||
              location.pathname.startsWith('/') ||
              location.pathname.startsWith('/admin')
          )

          // singleSpa.registerApplication(
          //   'app1',
          //   () => System.import('app1'),
          //   location =>
          //     location.pathname.startsWith('/app1') ||
          //     location.pathname.startsWith('/admin/app1')
          // )

          // singleSpa.registerApplication(
          //   'app2',
          //   () => System.import('app2'),
          //   location => location.pathname.startsWith('/app2')
          // )
          singleSpa.registerApplication(
            'hzq-system',
            () => System.import('hzq-system'),
            location => location.pathname.startsWith('/system')
          )

          singleSpa.start()
        })
      })()
    </script>
    <!-- See https://github.com/joeldenning/import-map-overrides#user-interface  -->
    <import-map-overrides-full
      show-when-local-storage="overrides-ui"
    ></import-map-overrides-full>
  </body>
</html>
